package com.drools.userguide._4_cashflow;

import com.drools.userguide._3_statefulSession.Fire;
import com.drools.util.Utils;
import org.kie.api.KieServices;
import org.kie.api.command.Command;
import org.kie.api.command.KieCommands;
import org.kie.api.runtime.ExecutionResults;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class Test {

    @org.junit.Test
    public void testCashflow() {
        KieServices kieServices = KieServices.Factory.get();
        KieContainer kContainer = kieServices.getKieClasspathContainer();
        KieSession kSession = kContainer.newKieSession();

        AccountPeriod accountPeriod = new AccountPeriod();
        Calendar calendar = Calendar.getInstance();
        calendar.set(2018, 2, 20);
        Date start = calendar.getTime();
        Utils.printDateNormal(start);
        calendar.set(2018, 2, 30);
        Date end = calendar.getTime();
        Utils.printDateNormal(end);
        accountPeriod.setStart(start);
        accountPeriod.setEnd(end);

        Account account = new Account(1);
        account.setBalance(1);

        CashFlow cashFlowInc = new CashFlow();
        cashFlowInc.accountNo = account.getAccountNo();
        cashFlowInc.setType(CashFlow.CREDIT);
        cashFlowInc.setAmount(100);
        Date cashDate = new Date();
        Utils.printDateNormal(cashDate);
        cashFlowInc.setDate(cashDate);

        kSession.insert(accountPeriod);
        kSession.insert(account);
        kSession.insert(cashFlowInc);

        CashFlow cashFlowDec = new CashFlow();
        cashFlowDec.accountNo = account.getAccountNo();
        cashFlowDec.setType(CashFlow.DEBIT);
        cashFlowDec.setAmount(100);
        cashFlowDec.setDate(cashDate);

        kSession.insert(cashFlowDec);
        kSession.fireAllRules();
    }



}
